package com.flash.BusinessParameters.service.impl;

import com.flash.BusinessParameters.entity.Cash;
import com.flash.BusinessParameters.mapper.CashMapper;
import com.flash.BusinessParameters.service.CashService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CashServiceImpl implements CashService {
    @Resource
    CashMapper cashMapper;
    @Override
    public int deleteCash(String cashId) {
        if(cashId!=null && !cashId.equals("")){
            return cashMapper.deleteCash(cashId);
        }else {
            return 0;
        }
    }

    @Override
    public int insertCash(Cash cash) {
        return cashMapper.insertCash(cash);
    }

    @Override
    public List<Cash> selectCash() {
        return cashMapper.selectCash();
    }

    @Override
    public int selectCountCash() {
        return cashMapper.selectCountCash();
    }


    @Override
    public List<Cash> selectCashMap(String accountName, int page, int limit) {
        HashMap map = new HashMap();
        map.put("accountName" , buildWhere(accountName));
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        return cashMapper.selectCashMap(map);
    }

    @Override
    public int updateCash(Cash cash) {
        return cashMapper.updateCash(cash);
    }

    public String buildWhere(String accountName){
        StringBuffer strWhere=new StringBuffer();
        if(accountName!=null && !accountName.equals("")){
            strWhere.append(" and accountName like '%" + accountName + "%'" );
        }
        return strWhere.toString();
    }

}
